package com.cskaoyan.mall.product.controller;

import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.FirstLevelCategoryDTO;
import com.cskaoyan.mall.product.dto.SecondLevelCategoryDTO;
import com.cskaoyan.mall.product.dto.ThirdLevelCategoryDTO;
import com.cskaoyan.mall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Macro_Ray
 * @since 2024/6/6 下午3:00
 */
@RestController
@RequestMapping("/admin/product/")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    // 获取一级分类
    @GetMapping("getCategory1")
    public Result<List<FirstLevelCategoryDTO>> getCategory1() {
        List<FirstLevelCategoryDTO> firstLevelCategory = categoryService.getFirstLevelCategory();
        return Result.ok(firstLevelCategory);
    }

    // 获取二级分类
    @GetMapping("getCategory2/{category1Id}")
    public Result<List<SecondLevelCategoryDTO>> getCategory2(@PathVariable("category1Id") Long category1Id) {
        List<SecondLevelCategoryDTO> secondLevelCategory = categoryService.getSecondLevelCategoryById(category1Id);
        return Result.ok(secondLevelCategory);
    }

    // 获取三级分类
    @GetMapping("getCategory3/{category2Id}")
    public Result<List<ThirdLevelCategoryDTO>> getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<ThirdLevelCategoryDTO> thirdLevelCategory = categoryService.getThirdLevelCategoryById(category2Id);
        return Result.ok(thirdLevelCategory);
    }
}
